/**
 * User: alesj
 * Date: 2005.3.11
 * Time: 14:51:31
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.generalynx.ecos.data.types;

import org.hibernate.HibernateException;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

/**
 * A type for Hibernate integer <tt>PersistentEnum</tt>
 * @see PersistentEnumType
 * @author Ales Justin
 */
public class IntPersistentEnumType extends PersistentEnumType {

    protected int sqlType() {
        return Types.SMALLINT;
    }

    protected void setNotNull(PreparedStatement st, Object value, int index) throws SQLException {
        st.setInt(index, ((IntPersistentEnum)value).toIntegerCode());
    }

    public Serializable disassemble(Object value) throws HibernateException {
        return (value == null) ? null : ((IntPersistentEnum) value).toIntegerCode();
    }
}
